<?php

namespace Admin\Controller;

use Think\Controller;

class AjaxController extends Controller {

    public function index() {
        
    }

    public function isTagNameUsed() {
        $param = I('post.param');
        $name = I('post.name');
        $tag_id = I('get.tag_id');
        if ($param && $name == 'tag_name') {
            if (D('Tag')->isTagNameUsed($param, $tag_id)) {
                $this->ajaxReturn(array('info' => '你输入的标签名已被使用', 'status' => 0));
            } else {
                $this->ajaxReturn(array('info' => '', 'status' => 'y'));
            }
        } else {
            $this->ajaxReturn(array('info' => '请输入标签名'));
        }
    }

    public function isTagAliasUsed() {
        $param = I('post.param');
        $name = I('post.name');
        $tag_id = I('get.tag_id');
        if ($param && $name == 'alias') {
            if (D('Tag')->isTagAliasUsed($param, $tag_id)) {
                $this->ajaxReturn(array('info' => '你输入的标签别名已被使用', 'status' => 0));
            } else {
                $this->ajaxReturn(array('info' => '', 'status' => 'y'));
            }
        } else {
            $this->ajaxReturn(array('info' => '请输入标签别名', 'status' => 0));
        }
    }

    public function isItemNameUsed() {
        $param = I('post.param');
        $name = I('post.name');
        $item_id = I('get.item_id');
        if ($param && $name == 'item_name') {
            if (D('Item')->isItemNameUsed($param, $item_id)) {
                $this->ajaxReturn(array('info' => '你输入的分类名已被使用', 'status' => 0));
            } else {
                $this->ajaxReturn(array('info' => '', 'status' => 'y'));
            }
        } else {
            $this->ajaxReturn(array('info' => '请输入分类名'));
        }
    }

    public function isItemAliasUsed() {
        $param = I('post.param');
        $name = I('post.name');
        $item_id = I('get.item_id');
        if ($param && $name == 'alias') {
            if (D('Item')->isItemAliasUsed($param, $item_id)) {
                $this->ajaxReturn(array('info' => '你输入的分类别名已被使用', 'status' => 0));
            } else {
                $this->ajaxReturn(array('info' => '', 'status' => 'y'));
            }
        } else {
            $this->ajaxReturn(array('info' => '请输入分类别名', 'status' => 0));
        }
    }

}
